/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ylystudio.pms.ejb.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Kenny Lin
 */
@Entity
@Table(name = "grade")
@NamedQueries({
    @NamedQuery(name = "Grade.findAll", query = "SELECT g FROM Grade g"),
    @NamedQuery(name = "Grade.findByGradeId", query = "SELECT g FROM Grade g WHERE g.gradeId = :gradeId"),
    @NamedQuery(name = "Grade.findByFinishNumber", query = "SELECT g FROM Grade g WHERE g.finishNumber = :finishNumber"),
    @NamedQuery(name = "Grade.findByFailNumber", query = "SELECT g FROM Grade g WHERE g.failNumber = :failNumber"),
    @NamedQuery(name = "Grade.findByMultiScore", query = "SELECT g FROM Grade g WHERE g.multiScore = :multiScore")})
public class Grade implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "grade_id")
    private Integer gradeId;
    @Basic(optional = false)
    @Column(name = "finish_number")
    private long finishNumber;
    @Basic(optional = false)
    @Column(name = "fail_number")
    private long failNumber;
    @Basic(optional = false)
    @Column(name = "multi_score")
    private double multiScore;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "grade", fetch = FetchType.LAZY)
    private List<ErrorMiddle> errorMiddleList;
    @JoinColumn(name = "user_id", referencedColumnName = "user_id")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User user;
    @JoinColumn(name = "gi_id", referencedColumnName = "gi_id")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private GradeItem gradeItem;

    public Grade() {
    }

    public Grade(Integer gradeId) {
        this.gradeId = gradeId;
    }

    public Grade(Integer gradeId, long finishNumber, long failNumber, double multiScore) {
        this.gradeId = gradeId;
        this.finishNumber = finishNumber;
        this.failNumber = failNumber;
        this.multiScore = multiScore;
    }

    public Integer getGradeId() {
        return gradeId;
    }

    public void setGradeId(Integer gradeId) {
        this.gradeId = gradeId;
    }

    public long getFinishNumber() {
        return finishNumber;
    }

    public void setFinishNumber(long finishNumber) {
        this.finishNumber = finishNumber;
    }

    public long getFailNumber() {
        return failNumber;
    }

    public void setFailNumber(long failNumber) {
        this.failNumber = failNumber;
    }

    public double getMultiScore() {
        return multiScore;
    }

    public void setMultiScore(double multiScore) {
        this.multiScore = multiScore;
    }

    public List<ErrorMiddle> getErrorMiddleList() {
        return errorMiddleList;
    }

    public void setErrorMiddleList(List<ErrorMiddle> errorMiddleList) {
        this.errorMiddleList = errorMiddleList;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public GradeItem getGradeItem() {
        return gradeItem;
    }

    public void setGradeItem(GradeItem gradeItem) {
        this.gradeItem = gradeItem;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (gradeId != null ? gradeId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Grade)) {
            return false;
        }
        Grade other = (Grade) object;
        if ((this.gradeId == null && other.gradeId != null) || (this.gradeId != null && !this.gradeId.equals(other.gradeId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ylystudio.pms.ejb.entity.Grade[gradeId=" + gradeId + "]";
    }

}
